jQuery.fn.defaultText = function() {
	$.each(this, function() {
		this.$$defText = this.value;
		$(this).addClass('default');
		$(this).focus(function() { if(this.$$defText == this.value) { this.value = ''; $(this).removeClass('default'); } });
		$(this).blur(function() { if(this.value == '') { this.value = this.$$defText; $(this).addClass('default'); } });
	});
	return this;
}
jQuery.call = function(number, name, desc, sucs, error) {
	$.ajax({
		url     : '/auth/call',
		type    : 'POST',
		dataType: 'json',
		data    : { number: number, name: name, desc: desc },
		success : function(data, textStatus, XMLHttpRequest) {
			if(data.status) sucs(data.data);
			else if(error) error(data.msg);
		},
		error   : function(XMLHttpRequest, textStatus, errorThrown) {
			error(XMLHttpRequest.responseText);
		}
	});
}

function normalCallForm() {
	$(document.callMe.number).removeClass('error');
	$(document.callMe.name).removeClass('error');
	$(document.callMe).find('.error-msg').hide().text(" ");
}

function errorCallForm(msg) {
	$(document.callMe.number).addClass('error');
	$(document.callMe.name).addClass('error');
	$(document.callMe).find('.error-msg').show().text(msg);
}

$(function() {
	$('.def-text').defaultText().focus(normalCallForm);
	$("#call-me-submit").click(function(){
		$.call($(document.callMe.number).val(), $(document.callMe.name).val(), $(document.callMe.desc).val(), function(data) {
			$(document.callMe).find('.sucs-msg').show().text('Ð¨Ð°Ð½Ð¾Ð²Ð½Ð¸Ð¹ '+data.call.name+' Ð²Ð°ÑˆÐ° Ð·Ð°Ñ�Ð²ÐºÐ° ÑƒÑ�Ð¿Ñ–ÑˆÐ½Ð¾ Ð²Ñ–Ð´Ð¿Ñ€Ð°Ð²Ð»ÐµÐ½Ð°.');
			setTimeout(function(){ window.location.reload(); }, 2000);
		}, function(msg) { errorCallForm(msg); });
	});
});